home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / strgstrg.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.7 KB  |  62 lines

  1. ;void  string_string(sub_strg,return_strg,length);
  2. ;  char  *sub_strg,*return_strg;
  3. ;  unsigned short  length;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _string_string
  11. _string_string proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     push si            ;
  16.     push ds            ;save DS
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    mov  _error_code,1    ;1 = error
  22.     cmp  _memory_model,2    ;data near or far?
  23.     jb   L1            ;jump if near
  24.     les  di,dword ptr[bp+8] ;ES:DI pts to return string
  25.     lds  si,dword ptr[bp+4] ;DS:SI pts to substring
  26.     add  bp,4        ;add 4 to BP since dword ptr
  27.     jmp  short L2        ;
  28. L1:    mov  di,[bp+6]        ;NEAR case
  29.     mov  si,[bp+4]        ;
  30.     mov  ax,ds        ;ES = DS
  31.     mov  es,ax        ;
  32. L2:    mov  byte ptr es:[di],0    ;return null string if error
  33.     mov  bx,si        ;save substring start pt
  34.     mov  cx,[bp+8]        ;return string length
  35.     jcxz L5            ;quit if null
  36.     cmp  byte ptr[si],0    ;test for null substring
  37.     je   L5            ;quit if null
  38. L3:    mov  al,[si]        ;get a char
  39.     inc  si            ;forward for next time
  40.     cmp  al,0        ;end of string?
  41.     jne  L4            ;jump if so
  42.     mov  si,bx        ;back to start of substrg
  43.     jmp  short L3        ;loop back
  44. L4:    mov  es:[di],al        ;else write the char
  45.     inc  di            ;forward return_string ptr
  46.     loop L3            ;go do next
  47.     mov  byte ptr es:[di],0    ;terminating null
  48.     pop  ds            ;restore DS
  49.     dec  _error_code    ;0 = no error
  50.     jmp  short L6        ;jump ahead
  51. L5:    pop  ds            ;terminate with error
  52. L6:    pop  si            ;
  53.     pop  di            ;
  54.     pop  bp            ;
  55.     cmp  _memory_model,0    ;quit
  56.     jle  quit        ;
  57.     db   0CBh        ;RET far
  58. quit:    ret            ;RET near
  59. _string_string ENDP
  60. _TEXT    ENDS
  61.     END
  62.